/*******************************************************************************************
 *  Bullet.c
 *
 *  Creating and managing Bullet object strucutres.
 *
 *******************************************************************************************/







/*******************************************************************************************
 *  INCLUDES :
 *******************************************************************************************/

/* System and library related : */
#include <stdlib.h>
#include <string.h>

/* Project related : */
#include "Bullet.h"







/*******************************************************************************************
 *  FUNCTIONS :
 *******************************************************************************************/

/*******************************************************************************************
 *  NEWBULLET : Creates an empty Bullet object structure.
 *******************************************************************************************/
Bullet *newBullet(void) {
	Bullet *b;

	/* Creating the container structure : */
	b = (Bullet *)malloc(sizeof(Bullet));


	/* Setting the object's type : */
	b->otype = bullet;


	/* Returning the still empty structure : */
	return b;

}




/*******************************************************************************************
 *  FREEBULLET : destroys a Bullet object structure and all the objects it stores.
 *******************************************************************************************/
void freeBullet(Bullet *b) {

	int i;

	if(b->direction != NULL)
		free(b->direction);

	if(b->speed != NULL)
		free(b->speed);

	//for(i=0; i<b->actionsNum; i++)
	//	free(b->actions[i]);
	for(i=0; i<b->actionRefsNum; i++)
		free(b->actionRefs[i]);

	free(b);
}




/*******************************************************************************************
 *	SETBULLETLABEL	 	: assignes a label to a Bullet object
 *  SETBULLETDIRECTION	: assignes a direction object to a Bullet object
 *  SETBULLETSPEED		: assignes a speed object to a Bullet object
 *  ADDBULLETACTION		: adds an action object to a Bullet object
 *  ADDBULLETACTIONREF	: adds an actionRef object to a Bullet object
 *******************************************************************************************/
void setBulletLabel(Bullet *b, char *l) {

	b->label = malloc(MAX_LABEL_LENGTH);
	
	strcpy(b->label, l);

}

void setBulletDirection(Bullet *b, Direction *d) {
	b->direction = d;
}

void setBulletSpeed(Bullet *b, Speed *s) {
	b->speed = s;
}

void addBulletAction(Bullet *b, Action *a) {
	b->actions[b->actionsNum] = a;
	b->actionsNum++;
}

void addBulletActionRef(Bullet *b, ActionRef *ar) {
	b->actionRefs[b->actionRefsNum] = ar;
	b->actionRefsNum++;
}
